##########################################################################################

library(data.table)
library(optparse)

##########################################################################################

option_list <- list(
    make_option(c("--raw_md5_file"), type = "character") ,
    make_option(c("--combine_md5_file"), type = "character") ,
    make_option(c("--out_name"), type = "character")
)

if(1!=1){
    
  raw_md5_file <- "~/20220915_gastric_multiple/rna_batch2/fastq/Raw.Fastq.srt.md5"
  combine_md5_file <- "~/20220915_gastric_multiple/rna_batch2/fastq/All.Fastq.srt.md5"
  out_name <- "~/20220915_gastric_multiple/rna_batch2/fastq_checkMd5/diff_sample.csv"
}

###########################################################################################

parseobj <- OptionParser(option_list=option_list, usage = "usage: Rscript %prog [options]")
opt <- parse_args(parseobj)
print(opt)

raw_md5_file <- opt$raw_md5_file
combine_md5_file <- opt$combine_md5_file
out_name <- opt$out_name

###########################################################################################

raw_md5 <- data.frame(fread(raw_md5_file , header = F))
combine_md5 <- data.frame(fread(combine_md5_file , header = F))

dat_diff <- raw_md5[which(!(raw_md5$V1 %in% combine_md5$V1)),]

result <- data.frame(sample=unique(sapply(strsplit(dat_diff$V2 , "_") , "[" , 1)))
write.csv( result , out_name , row.names = F , quote = F )